package com.pybox.api;

import com.pybox.entity.TCustomers;
import com.pybox.service.TCustomersService;
import com.pybox.dto.TCustomersDto;

import com.pybox.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.*;

/**
* 描述：TCustomers Api
* @author wuyingkai
* @date 2018-09-15
*/

@Slf4j
@ApiIgnore
@RequestMapping("/TCustomers")
@Api(tags = "TCustomers管理接口", description = "TCustomers管理接口")
@RestController
public class TCustomersApi {

    @Autowired
    private TCustomersService service;

    @ApiOperation(value = "创建TCustomers", notes = "创建TCustomers")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TCustomers dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除TCustomers", notes = "删除TCustomers")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TCustomers id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新TCustomers", notes = "更新TCustomers")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "TCustomers id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TCustomersDto dto) {
        service.update(id, dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询TCustomers", notes = "查询TCustomers")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TCustomers id", dataType = "String", paramType = "path")
    public Result<TCustomersDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询TCustomers", notes = "分页查询TCustomers")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query"),
           @ApiImplicitParam(name = "shortName", value = "shortName", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "name", value = "name", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "country", value = "country", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "province", value = "province", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "city", value = "city", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "address", value = "address", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "landline", value = "landline", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "telephone", value = "telephone", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "phone", value = "phone", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "email", value = "email", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "state", value = "state", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "contactName", value = "contactName", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "employeeNum", value = "employeeNum", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "comments", value = "comments", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "timezone", value = "timezone", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "deleted", value = "deleted", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "ctime", value = "ctime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "utime", value = "utime", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TCustomersDto>> page(
                        @RequestParam(required = false) Integer id,
                        @RequestParam(required = false) String shortName,
                        @RequestParam(required = false) String name,
                        @RequestParam(required = false) String country,
                        @RequestParam(required = false) String province,
                        @RequestParam(required = false) String city,
                        @RequestParam(required = false) String address,
                        @RequestParam(required = false) String landline,
                        @RequestParam(required = false) String telephone,
                        @RequestParam(required = false) String phone,
                        @RequestParam(required = false) String email,
                        @RequestParam(required = false) String state,
                        @RequestParam(required = false) String contactName,
                        @RequestParam(required = false) String employeeNum,
                        @RequestParam(required = false) String comments,
                        @RequestParam(required = false) String timezone,
                        @RequestParam(required = false) String deleted,
                        @RequestParam(required = false) String ctime,
                        @RequestParam(required = false) String utime,
                    @RequestParam(required = true) Integer pageNo,
                    @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();

                params.put("shortName",shortName);
                params.put("name",name);
                params.put("country",country);
                params.put("province",province);
                params.put("city",city);
                params.put("address",address);
                params.put("landline",landline);
                params.put("telephone",telephone);
                params.put("phone",phone);
                params.put("email",email);
                params.put("state",state);
                params.put("contactName",contactName);
                params.put("employeeNum",employeeNum);
                params.put("comments",comments);
                params.put("timezone",timezone);
                params.put("deleted",deleted);
                params.put("ctime",ctime);
                params.put("utime",utime);
        return Result.ok(service.page(pageNo, pageSize, params));
    }

    @ApiOperation(value = "根据customer_id查询TCustomers的名称", notes = "根据customer_id查询TCustomers的名称")
    @RequestMapping(value = "/details", method = RequestMethod.GET)
    public Result<TCustomersDto> details() {
        return Result.ok(service.detail());
    }

    @ApiOperation(value = "查询TCustomers", notes = "查询TCustomers")
    @RequestMapping(value = "/searchTcustomers", method = RequestMethod.GET)
    public Result<TCustomersDto> searchTcustomers() {
        return Result.ok(service.searchTcustomers());
    }

}